#!/usr/bin/env python3.0

#2520 is the smallest number that can be divided by each of the 
#numbers from 1 to 10 without any remainder.
#
#What is the smallest number that is evenly divisible by all of the numbers from 1 to 20?

from math import floor, log
from numth import prime_generator

def max_divisible(k):
    primes = [p for p in prime_generator(max=k)]
    powers = []
    
    for p in primes:
        if p * p > k:
            powers.append(1)
        else:
            powers.append(floor(log(k)/log(p)))
    
    result = 1
    
    for (p, n) in zip(primes, powers):
        result *= p ** n
    
    return result

if __name__ == '__main__':
    k = 20
    print('Result: {0}'.format(max_divisible(k)))
            